package com.ogawa.a7517.widget;

import android.graphics.Rect;
import android.util.Log;
import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

public class SpaceItemDecoration extends RecyclerView.ItemDecoration {
    private int topSpace;  //顶部间距
    private int leftSpace;//左边间距
    private int spaceCount;//列数

    public SpaceItemDecoration(int topSpace, int leftSpace, int spaceCount) {
        this.topSpace = topSpace;
        this.leftSpace = leftSpace;
        this.spaceCount = spaceCount;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
//        outRect.left = leftSpace * (parent.getChildAdapterPosition(view) % spaceCount);//由于第二列已经移动了一个间距，所以第三列要移动两个位移间距就能右边贴边，且item间距相等
//        if (parent.getChildAdapterPosition(view) >= spaceCount) {
        outRect.left = leftSpace / 2;
        outRect.right = leftSpace / 2;
        outRect.top = topSpace;
//        } else {
//            outRect.top = 0;
//        }
    }

}